#include "roundwidget.h"
#include "ui_roundwidget.h"
#include <QDebug>

RoundWidget::RoundWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RoundWidget)
{
    ui->setupUi(this);
    WHITE_PALYER = false;
    BLACK_PLAYER = true;
    current_chess = BLACK_PIECE;
    connect(ui->widget,&RingProgressBar::signalTimeOut,this,&RoundWidget::slotTimeOut);
}

void RoundWidget::slotPlayerChangeed(bool current_player)
{
    if(current_player == WHITE_PALYER)
        current_chess = WHITE_PIECE;
    else current_chess = BLACK_PIECE;
    update();
    ui->widget->slotPlayerChanged(current_player);
}

void RoundWidget::slotTimeOut()
{
    emit signalTimeOut(current_chess);
}

void RoundWidget::slotGameOver(int)
{
    ui->widget->gameOver();
}

void RoundWidget::slotNewGame()
{
    current_chess = BLACK_PIECE;
    update();
    ui->widget->newGame();
}

void RoundWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setPen(Qt::NoPen);
    QColor chess_color;

    //画出当前棋子
    if(current_chess == WHITE_PIECE)
    {
        chess_color = Qt::white;
        painter.setBrush(QBrush(chess_color));
    }
    else
    {
        chess_color = Qt::black;
        painter.setBrush(QBrush(chess_color));
    }
    painter.drawEllipse(100,50,40,40);

}

RoundWidget::~RoundWidget()
{
    delete ui;
}
